package xfsale.service.impl.j2ee;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import xfsale.packet.SysParamRequest;
import xfsale.packet.SysParamResponse;

public final class SysParam extends BaseService {

	private SysParamRequest request;
	private SysParamResponse response;

	public SysParam(SysParamRequest request, SysParamResponse response) {
		super(request, response);

		this.request = request;
		this.response = response;

		response.returnCode = "0000";
		response.returnMsg = "获取系统参数成功";
	}

	//功能处理
    @Override
	protected void process() throws Exception {
		//初始化系统参数


		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			logger.debug("获取系统参数...");
			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('DistributorCode') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.distributorCode = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('SysStatus') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.status = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('WorkDay') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.workDay = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('NextWorkDay') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.nextWorkDay = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('LogLevel') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.logLevel = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('LogTo') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.logTo = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('LogFile') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.logFile = rs.getString(1);
			stmt.close();

			stmt = conn.prepareStatement("" +
				"select paramValue from SysParam " +
				"where upper(paramKey) = upper('SysVersion') "
			);
			rs = stmt.executeQuery();
			rs.next();
			response.version = rs.getString(1);
			stmt.close();

			logger.debug("获取系统参数成功.");
		} catch (Exception e) {
			logger.error("获取系统参数出错. " + e);
			throw e;
		} finally {
			stmt.close();
		}
	}

}